<?php
/*
###########################################################################
#                                  KALMAR                                 #
#                      http://akkar.sourceforge.net/                      #
#                                                                         #
#                            -------------------                          #
#                               visperson.php                             #
#                            -------------------                          #
#                                                                         #
#   copyright (C) 2004 Roy W. Andersen                                    #
#   email: ensnared@gmail.com                                             #
#                                                                         #
###########################################################################

###########################################################################
#                                                                         #
#  This program is free software; you can redistribute it and/or modify   #
#  it under the terms of the GNU General Public License as published by   #
#  the Free Software Foundation; either version 2 of the License, or      #
#  (at your option) any later version.                                    #
#                                                                         #
###########################################################################
*/
define('IN_KALMAR', true);
include('common.php');

if ($_POST['edited']) {
	oppdater_personinfo();
	$_SESSION['message'] .= $LANG['MESSAGE']['person_updated'];
	header('Location: ./'.$_POST['whereiwas'].'?person_id='.$_POST['person_id'].'&spill_id='.$spill_id);
	exit();
} elseif ($_POST['nytt_passord']) {
	if (is_modifiable()) {
		if (nytt_passord()) {
			$_SESSION['message'] = $LANG['MESSAGE']['password_changed'];
		} else {
			$_SESSION['message'] = $LANG['MESSAGE']['password_change_error'];
		}
	}
	header('Location: ./'.$_POST['whereiwas'].'?person_id='.$_POST['person_id']);
	exit();
} elseif($_GET['lock_bruker']) {
	if (is_admin() && !is_last_admin($_GET['lock_bruker'])) {
		lock_bruker();
		$_SESSION['message'] = $LANG['MESSAGE']['account_locked'];
	}
	header('Location: ./visperson.php?person_id='.$_GET['lock_bruker']);
	exit();
}

include('header.php');
$person_id = $_GET['person_id'];
echo person_sheet($person_id);
$person = get_person($person_id);

	echo '
		<hr width="50%">
		<h2 align="center">'.$LANG['MISC']['history'].'</h2>
		<br>
		<table align="center" cellspacing="0" width="50%">
			<tr class="highlight">
				<td>'.$LANG['MISC']['game'].'</td>
				<td>'.$LANG['MISC']['character_s'].'</td>
			</tr>
	';
	$spill = get_spillhistorikk($person['person_id']);
	if ($spill) {
		foreach ($spill as $spillinfo) {
			$historikk[$spillinfo['spill_id']]['spillnavn'] = $spillinfo['navn'];
			$historikk[$spillinfo['spill_id']]['spill_id'] = $spillinfo['spill_id'];
		}
	} else {
		$historikk[0]['spillnavn'] = $LANG['MISC']['none'];
	}
	unset($spill);
	foreach ($historikk as $data) {
		echo '
			<tr>
		';
		if (strtolower($data['spillnavn']) != strtolower($LANG['MISC']['none'])) {
			echo '
				<td nowrap><a href="./vispaamelding.php?person_id='.$person['person_id'].'&amp;spill_id='.$data['spill_id'].'">'.$data['spillnavn'].'</a></td>
				<td>
			';
			if ($roller = get_spiller_roller($person['person_id'], $data['spill_id'])) {
				$numroller[$data['spill_id']] = 0;
				foreach ($roller as $rolle) {
					if (is_related($rolle['rolle_id'], $rolle['spill_id'])) {
						echo '<a href="./visrolle.php?rolle_id='.$rolle['rolle_id'].'&amp;spill_id='.$rolle['spill_id'].'">'.$rolle['navn'].'</a><br>';
						$numroller[$rolle['spill_id']]++;
					}
				}
				if ($numroller[$data['spill_id']] === 0) {
					echo $LANG['MISC']['unknown'];
				}
			} else {
				echo $LANG['MISC']['none'];
			}
			echo '
				</td>
			';
		} else {
			echo '
				<td>'.$LANG['MISC']['none'].'</td>
				<td>'.$LANG['MISC']['none'].'</td>
			';
		}
		echo '
			</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		';
	}
	echo '
		<tr>
			<td>&nbsp;</td>
		</tr>
	</table>';

include('footer.php');
?>
